﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 简单记事本
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button_logIn_Click(object sender, EventArgs e)
        {
            if (textBox_user.Text == "admin" && textBox_pwd.Text == "admin")
            {
                MessageBox.Show("登陆成功");
                panel_LogIn.Visible = false;
                panel_note.Visible = true;
                textBox_note.Focus();
            }
            else
            {
                MessageBox.Show("输入用户名或密码错误");
                textBox_user.Focus();
            }
        }

        private void button_Clear_Click(object sender, EventArgs e)
        {
            textBox_pwd.Clear();
            textBox_user.Clear();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            panel_LogIn.Visible = true;
            panel_note.Visible = false;
            textBox_note.WordWrap = false;
        }

        private void button_AutoR_Click(object sender, EventArgs e)
        {
            textBox_note.WordWrap = !textBox_note.WordWrap;
            button_AutoR.Text = (textBox_note.WordWrap) ? ("取消自动换行") : ("自动换行");
        }

        private void button_Save_Click(object sender, EventArgs e)
        {
            using (FileStream fw = new FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.Write))
            {
                byte[] buff = Encoding.Default.GetBytes(textBox_note.Text);
                fw.Write(buff, 0, buff.Length);
            }
        }
    }
}
